﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Shapes;

namespace FourPartHarmony3 {
    enum ScoreElementType {
        DUMMY,
        SMALL_DEGREE_1,
        SMALL_DEGREE_2,
        SMALL_DEGREE_3,
        SMALL_DEGREE_4,
        SMALL_DEGREE_5,

        SMALL_DEGREE_6,
        SMALL_DEGREE_7,
        CENTER_DOT,
        METER_2,
        METER_3,

        METER_4,
        METER_5,
        METER_6,
        METER_7,
        METER_8,

        DOUBLE_SHARP,
        DOUBLE_FLAT,
        CHORD_BASE_1,
        INTERNAL_KEY_UP,
        INTERNAL_KEY_UP_P,
        INTERNAL_KEY_P,
        INTERNAL_KEY_TRIANGLE,
        INTERNAL_KEY_PLUS_TRIANGLE,
        INTERNAL_KEY_PLUS,
        INTERNAL_KEY_MINUS,
        INTERNAL_KEY_MINUS_MINUS,
        INTERNAL_KEY_CIRCLE,
        INTERNAL_KEY_CIRCLE_MINUS,
        INTERNAL_KEY_MINUS_CIRCLE,
        INTERNAL_KEY_MINUS_CIRCLE_MINUS,

        INTERNAL_KEY_7,
        INTERNAL_KEY_6,
        INTERNAL_KEY_5,
        INTERNAL_KEY_4,
        INTERNAL_KEY_3,

        INTERNAL_KEY_2,
        INTERNAL_KEY_1,
        INTERNAL_KEY_END,
        INTERNAL_KEY_START,
        CHORD_LOWERED,
        CHORD_RAISED,

        CHORD_PLUS,
        CHORD_MINUS,
        UPPER_CHORD_PLUS,
        UPPER_CHORD_CIRCLE,
        UPPER_7,
        UPPER_6,

        UPPER_5,
        UPPER_4,
        UPPER_3,
        UPPER_2,
        FOURTH_INVERSION,

        THIRD_INVERSION,
        SECOND_INVERSION,
        FIRST_INVERSION,
        NINTH,
        SEVENTH,

        CHORD_STRIKE,
        CHORD_PLUS6,
        CHORD_PLUS46,
        CHORD_CIRCLE,
        CHORD_7,

        CHORD_6,
        CHORD_5,
        CHORD_4,
        CHORD_3,
        CHORD_2,

        CHORD_1,
        DOT_2,
        DOT,
        REST_1,
        REST_2,

        REST_4,
        REST_8,
        REST_16,
        GCLEF,
        FCLEF,

        NOTE_16_INV,
        NOTE_16,
        NOTE_8_INV,
        NOTE_8,
        NOTE_4_INV,

        NOTE_4,
        NOTE_2_INV,
        NOTE_2,
        NOTE_1,
        SHARP,

        NATURAL,
        FLAT,
        DOUBLE_BAR,
        STANDARD_BAR,
        END_BAR,

        LARGE_PAREN,
        LEDGER_LINE,
        NUM
    }

    class ScoreElementPathes {
        public struct Item {
            public ScoreElementType type;
            public Path path;
            public string name;
            public Rect boundary;

            public Item(string aName, Rect aBoundary) {
                type = ScoreElementType.NUM;
                path = null;
                name = aName;
                boundary = aBoundary;
            }
        };

        static Item [] mItems = new Item[] {
            new Item("dummy", new Rect(0, 0, 1, 1)),
            new Item("smallInterval1", new Rect(23, -5, 1, 10.8999938964844)),
            new Item("smallInterval2", new Rect(20, -5, 4.60000228881836, 10.9000062942505)),
            new Item("smallInterval3", new Rect(20, -5, 6.57500457763672, 10.9130077362061)),
            new Item("smallInterval4", new Rect(20, -5, 8.19902372360229, 10.9000062942505)),
            new Item("smallInterval5", new Rect(20, -5, 7.30000686645508, 10.9000062942505)),
            new Item("smallInterval6", new Rect(20, -5, 8.64999771118164, 10.2000179290771)),
            new Item("smallInterval7", new Rect(20, -5, 10, 10)),
            new Item("centerDotPath", new Rect(0, 0, 1.89999997615814, 1.89999997615814)),
            new Item("tempo2Path", new Rect(-6, -8, 14.3450002670288, 19.57688331604)),
            new Item("tempo3Path", new Rect(-5, -8, 11.8000001907349, 19)),
            new Item("tempo4Path", new Rect(-6, -7, 12.6999998092651, 15.3999996185303)),
            new Item("tempo5Path", new Rect(-5, -10, 11.8061456680297, 19.6830005645752)),
            new Item("tempo6Path", new Rect(-5, -9, 10.8999996185303, 17.2000007629395)),
            new Item("tempo7Path", new Rect(-5, -8, 13.882300376892, 19.0900001525879)),
            new Item("tempo8Path", new Rect(-6, -8, 11.3500003814697, 17.1989994049072)),
            new Item("doubleSharpPath", new Rect(-17, -4, 8.19999980926514, 9.10000038146973)),
            new Item("doubleFlatPath", new Rect(-21, -14, 12.9250001907349, 21.25)),
            new Item("chordBase1Path", new Rect(0, 9, 1, 7.19999980926514)),
            new Item("internalKeyUpPath", new Rect(0, -7, 4, 9)),
            new Item("internalKeyUpPPath", new Rect(0, -7, 6, 9)),
            new Item("internalKeyPPath", new Rect(0, -7, 4, 9)),
            new Item("internalKeyTrianglePath", new Rect(0, -7, 4, 9)),
            new Item("internalKeyPlusTrianglePath", new Rect(0, -14, 9, 9)),
            new Item("internalKeyPlusPath", new Rect(-12, -5, 4.59999990463257, 4.59999990463257)),
            new Item("internalKeyMinusPath", new Rect(-12, -5, 4.59999990463257, 4.59999990463257)),
            new Item("internalKeyMinusMinusPath", new Rect(-17, -5, 10, 4.59999990463257)),
            new Item("internalKeyCirclePath", new Rect(-9, -4, 3.25, 3.25)),
            new Item("internalKeyCircleMinusPath", new Rect(-14, -4, 5+3.25, 3.25)),
            new Item("internalKeyMinusCirclePath", new Rect(-14, -4, 5+3.25, 3.25)),
            new Item("internalKeyMinusCircleMinusPath", new Rect(-18, -4, 9+3.25, 3.25)),
            new Item("internalKey7Path", new Rect(-7, -7, 10.8809995651245, 9.64400005340576)),
            new Item("internalKey6Path", new Rect(-6, -7, 9.10000038146973, 9.55000019073486)),
            new Item("internalKey5Path", new Rect(-4, -7, 6.84999990463257, 9.55000019073486)),
            new Item("internalKey4Path", new Rect(-4, -7, 8.19999980926514, 9.64999961853027)),
            new Item("internalKey3Path", new Rect(-3, -7, 6.33799976110458, 9.66199970245361)),
            new Item("internalKey2Path", new Rect(-1, -7, 3.70000004768372, 9.55000019073486)),
            new Item("internalKey1Path", new Rect(0, -7, 1, 8.55000019073486)),
            new Item("internalKeyEndPath", new Rect(-9, -8, 4.00399971008301, 17.8075542449951)),
            new Item("internalKeyStartPath", new Rect(6, -8, 4.00355339050293, 17.8075542449951)),
            new Item("chordLoweredPath", new Rect(-8, -6, 3.6079797744751, 6.26952886581421)),
            new Item("chordRaisedPath", new Rect(-4.5, -12, 3.6079797744751, 6.26952886581421)),
            new Item("chordPlusPath", new Rect(-17, -3, 5.5, 5.5)),
            new Item("chordMinusPath", new Rect(-17, -3, 5.5, 5.5)),
            new Item("upperChordPlusPath", new Rect(-9, -12, 4.59999990463257, 4.59999990463257)),
            new Item("upperChordCirclePath", new Rect(-7, -11, 3.25, 3.25)),
            new Item("upper7Path", new Rect(-4, -13, 8.60799962282181, 6.96199989318848)),
            new Item("upper6Path", new Rect(-4, -12, 6.80599999427795, 6.96299982070923)),
            new Item("upper5Path", new Rect(-2, -12, 5.86679792404175, 7.12354612350464)),
            new Item("upper4Path", new Rect(-2, -12, 6.84999990463257, 6.84999990463257)),
            new Item("upper3Path", new Rect(-2, -13, 5.5, 6.96299982070923)),
            new Item("upper2Path", new Rect(-1, -13, 3.71900010108948, 7.4689998626709)),
            new Item("fourthInversionPath", new Rect(9, -9, 5, 7.24700021743774)),
            new Item("thirdInversionPath", new Rect(9, -9, 4.59999990463257, 7.75)),
            new Item("secondInversionPath", new Rect(9, -8, 4.59999990463257, 6.84999990463257)),
            new Item("firstInversionPath", new Rect(9, -9, 5.5, 7.30000019073486)),
            new Item("ninthPath", new Rect(9, 0, 4.59999990463257, 7.30000019073486)),
            new Item("seventhPath", new Rect(9, 1, 4.68201494216919, 6.80000019073486)),
            new Item("chordStrikePath", new Rect(-9, -3, 16.9817428588867, 6.7927303314209)),
            new Item("chordPlus6Path", new Rect(7, 0, 12.25, 7.74999988079071)),
            new Item("chordPlus46Path", new Rect(9, -5, 12.25, 16.7499998211861)),
            new Item("chordCirclePath", new Rect(-14, -2, 5.05000019073486, 5.05000019073486)),
            new Item("chord7Path", new Rect(-10, -6, 19.902000427246, 12.7019996643066)),
            new Item("chord6Path", new Rect(-8, -6, 16.3000001907349, 12.6999998092651)),
            new Item("chord5Path", new Rect(-5, -6, 11.3500003814697, 12.6999998092651)),
            new Item("chord4Path", new Rect(-7, -6, 16.3000001907349, 12.6999998092651)),
            new Item("chord3Path", new Rect(-8, -6, 15.8500002622604, 12.6999998092651)),
            new Item("chord2Path", new Rect(-5, -6, 10.8999996185303, 12.6999998092651)),
            new Item("chord1Path", new Rect(-2, -6, 5.5, 13.6000003814697)),
            new Item("dot2Path", new Rect(11, -1, 9.55000019073492, 3.25)),
            new Item("dotPath", new Rect(9, -3, 2.79900002479553, 2.79999995231628)),
            new Item("rest1Path", new Rect(-4, 0, 9.10000038146973, 4.59999990463257)),
            new Item("rest2Path", new Rect(-4, -4, 9.10000038146973, 4.59999990463257)),
            new Item("rest4Path", new Rect(-2, -12, 9.10019111633301, 24.4712162017822)),
            new Item("rest8Path", new Rect(-5, -3, 9.42298316955566, 13.8111190199852)),
            new Item("rest16Path", new Rect(-6, -7, 12.5436964035034, 25.0777778029442)),
            new Item("gclefPath", new Rect(-12, -36, 19.9874192476272, 59.5009986758232)),
            new Item("fclefPath", new Rect(-7, -8, 24.8719500899314, 27.5499992370605)),
            new Item("note16InvPath", new Rect(-5, -4, 10.958228111267, 32.8962516784668)),
            new Item("note16Path", new Rect(-5, -31, 18.1582278609276, 36.0763282775879)),
            new Item("note8InvPath", new Rect(-5, -4, 10.5924844741821, 31.9962501525879)),
            new Item("note8Path", new Rect(-5, -31, 19.5082283020019, 36.0763279795647)),
            new Item("note4InvPath", new Rect(-5, -4, 10.5924844741821, 32.4462509155273)),
            new Item("note4Path", new Rect(-5, -31, 10.5920238494873, 36.0763279795647)),
            new Item("note2InvPath", new Rect(-5, -4, 10.5920238494873, 32.4462509155273)),
            new Item("note2Path", new Rect(-5, -31, 10.5920238494873, 36.0763279795647)),
            new Item("note1Path", new Rect(-5, -4, 10.5800132751465, 9.00955295562744)),
            new Item("sharpPath", new Rect(-16, -13, 8.19999980926514, 26.6499996185303)),
            new Item("naturalPath", new Rect(-15, -13, 5.94999980926514, 27.0990009307861)),
            new Item("flatPath", new Rect(-14, -14, 6.43673658370972, 20.7108364105225)),
            new Item("doubleBarPath", new Rect(0.5, -18, 6.5, 38)),
            new Item("standardBarPath", new Rect(-1, -18, 1, 38)),
            new Item("endBarPath", new Rect(-9, -17, 10.4499996900558, 36.101001739502)),
            new Item("largeParen", new Rect(-16, -65, 14.2505550384521, 126.125984191895)),
            new Item("ledgerLinePath", new Rect(-8, 0, 16, 1)),
        };

        public static void Prepare() {
            for (int i = 0; i < (int)ScoreElementType.NUM; ++i) {
                mItems[i].type = (ScoreElementType)i;
                mItems[i].path = Application.Current.FindResource(mItems[i].name) as Path;
                System.Diagnostics.Debug.Assert(mItems[i].path != null);
            }
        }

        public static Item PathItem(ScoreElementType t) {
            return mItems[(int)t];
        }

        public static Path Path(ScoreElementType t) {
            return mItems[(int)t].path;
        }

        public static string Name(ScoreElementType t) {
            return mItems[(int)t].name;
        }

        public static Rect Boundary(ScoreElementType t) {
            return mItems[(int)t].boundary;
        }

        public static int Num() {
            return (int)ScoreElementType.NUM;
        }
    }
}
